#include "client.h"
#include "router.h"
#include "tunnel.h"
#include <unistd.h>



Client::Client (const Config& cfg) : _cfg(cfg) {
  TRACE
  _tunnel = new Tunnel(this, cfg);
  _router = new Router(this, cfg);
}


void Client::run () {
  TRACE
  _tunnel->startup(_router);
  _router->startup(_tunnel);
  sleep(0xFFFFFFFF);
}


void Client::shutdown () {
  TRACE
  std::lock_guard<std::mutex> lock {_close_mutex};
  if (_closed)
    return;
  _closed = true;
  _router->shutdown();
  _tunnel->shutdown();
}

